{extend name="common/base_page" /}

{block name="title"}修改登录密码{/block}

{block name="jscssfile"}{/block}

{block name="css"}
<script>
var yzmUrl = "{:url('index/index/captcha')}?soure=editpwd&key={$captcha_key}";
</script>
<style type="text/css">
.m-b20{margin-bottom: 20px;}
.layui-form-label {
    padding: 9px 0px;
    width: 120px;
    line-height: 20px;
}
.captcha-div,.phone-code-div{
  display: flex;
}
.captcha-div img{
  width:110px;height:40px;cursor: pointer;
}
#captcha_code{width:180px;margin-right:15px;}
#oldpwd,#pwd,#pwd1{width:306px;}
</style>
{/block}

{block name="body"}

<div class="layui-fluid">
    <div class="layui-row">
      <div class="layui-col-md12">
              <div class="layui-card">
                  <div class="layui-card-header">新密码修改前需要验证原登录密码</div>
                  <div class="layui-card-body">
                      <div class="layui-row layui-form-item m-b20">
                          <div class="layui-col-lg12">
                              <label class="layui-form-label">图形验证码：</label>
                              <div class="layui-input-block captcha-div">
                                <input type="text" id="captcha_code" placeholder="输入图形验证码" maxlength="10" autocomplete="off" class="layui-input">
                                <img src="" alt="点击更换验证码"/>
                              </div>
                          </div>
                       </div>
                      <div class="layui-row layui-form-item m-b20">
                          <div class="layui-col-lg12">
                              <label class="layui-form-label">原登录密码：</label>
                              <div class="layui-input-block">
                                <input type="password" id="oldpwd" placeholder="输入原登录密码" maxlength="20" autocomplete="off" class="layui-input">
                              </div>
                          </div>
                      </div>
                      <div class="layui-row layui-form-item m-b20">
                          <div class="layui-col-lg12">
                              <label class="layui-form-label">新登录密码：</label>
                              <div class="layui-input-block">
                                <input type="password" id="pwd" placeholder="输入新登录密码" maxlength="20" autocomplete="off" class="layui-input">
                              </div>
                          </div>
                      </div>
                      <div class="layui-row layui-form-item m-b20">
                          <div class="layui-col-lg12">
                              <label class="layui-form-label">重复新密码：</label>
                              <div class="layui-input-block">
                                <input type="password" id="pwd1" placeholder="输入新登录密码" maxlength="20" autocomplete="off" class="layui-input">
                              </div>
                          </div>
                       </div>

                      <div class="layui-input-block m-b20">
                          <button class="layui-btn layui-btn-normal" onclick="_editAction();">保存</button>
                          <button class="layui-btn layui-btn-primary" onclick="window.parent._Index.closedialogLayer();">关闭</button>
                      </div>

                  </div>
              </div>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script type="text/javascript">
$(function(){
    //点击刷新验证码
    $('.captcha-div img').click(function(){ _setNewCaptcha(); });
    //设置验证码
    _setNewCaptcha();
    $('#captcha_code').focus();
});
//设置验证码
function _setNewCaptcha()
{
  $('.captcha-div img').attr('src',yzmUrl + '&t=' + Math.random());
  $('#captcha_code').val('');
}
//修改事件
function _editAction()
{
  var param = {
    editmode::'{$edit_mode}',
    captcha_key:'{$captcha_key}',
    captcha:$.trim($('#captcha_code').val()),
    code:$.trim($('#oldpwd').val()),
    pwd:$.trim($('#pwd').val()),
    pwd1:$.trim($('#pwd1').val()),
  };
  if(param.captcha == '' || param.captcha.length <= 0)
  {
    layer.msg('请输入图形验证码', {time: 2000,anim: 4});
    return false;
  }
  if(param.code == '' || param.code.length <= 0)
  {
    layer.msg('请输入原登录密码', {time: 2000,anim: 4});
    return false;
  }
  if(param.pwd == '' || param.pwd.length <= 0)
  {
    layer.msg('请输入新的登录密码', {time: 2000,anim: 4});
    return false;
  }
  if(param.pwd.length < 6 || param.pwd.length > 18)
  {
    layer.msg('密码长度限制在6至18位', {time: 2000,anim: 4});
    return false;
  }
  if(param.pwd != param.pwd1)
  {
    layer.msg('两次输入的密码不一致', {time: 2000,anim: 4});
    return false;
  }
  _Index.ajax("{:url('index/clinic.admin/edit_password')}",param,function(d){
    if(d.err == 0)
    {
      $('#captcha_code').val('');
      $('#oldpwd').val('');
      $('#pwd').val('');
      $('#pwd1').val('');
      layer.msg(d.msg, {time: 1000},function(){ 
        window.top.location.reload();
      });
    }else{
      //重新 设置验证码
      _setNewCaptcha();
      layer.msg(d.msg, {time: 2000,anim: 4});
    }
  },'请稍候...');
}
</script>
{/block}